<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();%>
<%String contextPath = request.getContextPath();%>
<jsp:include page="inc.jsp" />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<script type="text/javascript" charset="UTF-8">
	var loginAndRegDialog;

	$(function() {
		loginAndRegDialog = $("#loginAndRegDialog");
		// 将div渲染程dialog
		loginAndRegDialog.dialog({
			closable : false,
			modal : true,
			buttons : [ {
				text : '注册',
				handler : function() {
					//注册
				}
			}, {
				text : '登陆',
				handler : function() {
					$.ajax({
						type : "POST", // 请求方式 ("POST" 或 "GET")， 默认为 "GET"
						url : getCurProjPath() + '/Login',
						/*data : {	// 发送到服务器的数据
							name : $("#loginInputForm input[name=name]").val(),
							password : $("#loginInputForm input[name=password]").val()
						},*/
						data : $("#loginInputForm").serialize(),
						cache : false,	// 不缓存此页面
						dataType : 'json',	// 预期服务器返回的数据类型。
						success : function(data, textStatus) {	// 请求成功后的回调函数
							//console.info(data);
							//console.info(data.msg);
							//$.messager.alert('标题',data.msg);
							if (data && data.success) {	// 成功, 隐藏dialog
								loginAndRegDialog.dialog('close');
							 	$.messager.show({
									title : "提示",
									msg : data.msg,
									timeout:2000,
								}); 
								window.location.href ="main.jsp";
							} else { // 失败, 弹 对话框
								$.messager.alert('标题',data.msg);
							}
							
						},
						error : function (XMLHttpRequest, textStatus, errorThrown) {
							console.info("Ajax 执行失败");
						}
					});
				}
			} ]
		});
	});
	// 获取项目的URL
	function getCurProjPath() {
		var curWwwPath = window.document.location.href;
		var pathName = window.document.location.pathname;
		var pos = curWwwPath.indexOf(pathName);
		var localhostPath = curWwwPath.substring(0, pos);
		var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
		return (localhostPath + projectName);
	}
</script>
	<style type="text/css">
		/* 标签居右  */
		th{
			text-align: right;
		}
	</style>
<body style="width:100%;height:100%;">
	<div id="loginAndRegDialog"
		title="用户登陆"
		style="width:250px;height:200px;"	
	>
		<form id="loginInputForm" action="post">
			<table>
				<tr>
					<th>账户：</th>
					<td><input name="userName" type="text"/></td>
				</tr>
				<tr>
					<th>密码：</th>
					<td><input name="passWord" type="password"/></td>
				</tr>
			</table>
		</form>
	</div>
</body>
</html>